package com.gitee.grower

import com.gitee.grower.core.scheme.Scheme
import ink.ptms.chemdah.util.conf
import taboolib.common.platform.Plugin
import taboolib.common.platform.function.getDataFolder
import taboolib.common.platform.function.info
import taboolib.common.platform.function.releaseResourceFile
import taboolib.module.configuration.Config
import taboolib.module.configuration.Configuration
import java.io.File

object ItemGrower : Plugin() {

    @Config
    lateinit var config: Configuration

    val appendAmount: String?
        get() = config.getString("append-amount")

    val checkPrefix: String?
        get() = config.getString("check-prefix")

    val checkSuffix: String?
        get() = config.getString("check-suffix")

    val appendAddonLore: String
        get() = config.getString("append-addon","(+{0})")!!

    val negativePrefix: String
        get() = config.getString("negative-prefix")!!

    val negativeSuffix: String
        get() = config.getString("negative-suffix")!!

    val descriptionTempSuccess: String
        get() = config.getString("description-temp-s","{0} {1}")!!

    val descriptionTempFail: String
        get() = config.getString("description-temp-f","{0} {1}")!!

    override fun onEnable() {
        ItemGrowerAPI.schemes.clear()
        releaseResourceFile("scheme/example.yml")
        File(getDataFolder(),"scheme").toYamlListFiles().forEach {
            ItemGrowerAPI.registerScheme(it)
            info("Loaded scheme ${it.nameWithoutExtension}")
        }
    }


    fun File.toYamlListFiles() : List<File> {
        if (this.isDirectory) {
            return this.listFiles()?.flatMap { it.toYamlListFiles() } ?: emptyList()
        }

        if (this.extension == "yml") {
            return listOf(this)
        }

        return emptyList()
    }

}